package com.jdiv.samples.tutor4;

import com.jdiv.JDiv;
import com.jdiv.JProcess;

public class WormHead extends JProcess{
	
private int
ix;
private int iy;
private int apple_id;

public WormHead(int x,int y, int ix, int iy){
	this.x=x;
	this.y=y;
	this.ix=ix;
	this.iy=iy;
	
}

public void begin(){
    // Puts the graphic
	 graph=2;  
	 
    // And a worm body is created, that creates the other ones
    new WormSegment(128,priority+1);

  do{
	  frame();        

        // Checks cursor keys, and changes increments
        if (key(_RIGHT)){
            ix=8; iy=0;
        }
        if (key(_LEFT)){
            ix=-8; iy=0;
        }
        if (key(_DOWN)){
            ix=0; iy=8;
        }
        if (key(_UP)){
            ix=0; iy=-8;
        }

     /*  // Checks if worm has collided with apple
        if (apple_id==collision("Apple")){
            // Eliminates that apple
            signal(apple_id,s_kill);
            Main.apples--;         // Reduces apples' counter
            Main.worm_length+=4;   // Increments worm's tail
            Main.score+=10;        // Adds 10 points to score
      } */ 
        // Moves worm on the desired direction
        x=x+ix;
        y=y+iy;
    //    System.out.println("PIXEL: "+JDiv.get_pixel(x,y));
    // Repeats until it crashes with the wall (get_pixel) or
    // with it's own body
 //  }while(get_pixel(x,y)!=0 || collision("WormSegment"));
  
        
  }while(!collision("WormSegment"));

  // Checks if topscore has been reached, and refreshes it
    if(Main.score>Main.topscore){
        Main.topscore=Main.score;
    }

    // Reinitiates score and tail length variables
    Main.score=0;
    Main.worm_length=8;
    // Eliminates all worm_segment type process
 //   signal(son,s_kill_tree);
    // Creates a new worm, creating it's head
    new WormHead(8,96,8,0);
  }
}